package com.dtx.abstractfactory.tablefactory;

import com.dtx.abstractfactory.factory.Item;
import com.dtx.abstractfactory.factory.Page;

import java.util.Iterator;

/**
 * 具体的产品: TablePage类
 * TablePage类是Page类的子类。这里应该不需要我再详细说明了。与ListPage类比较一下。
 * 应该就能理解它们之间的对应关系
 */
public class TablePage extends Page {


    public TablePage(String title, String author) {
        super(title, author);
    }

    @Override
    public String makeHTML() {
        StringBuffer buffer = new StringBuffer();

        buffer.append("<html><head><title>" + title + "</title></head>\n");

        buffer.append("<body>\n");

        buffer.append("<h1>" + title + "<h1>\n");

        buffer.append("<table width=\"80%\" border=\"3\">\n");

        Iterator<Object> it = content.iterator();

        while (it.hasNext()) {
            Item item = (Item) it.next();
            buffer.append("<tr>" + item.makeHTML() + "</tr>");
        }

        buffer.append("</table>\n");

        buffer.append("<hr><address>" + author + "</address>");

        buffer.append("</body></html>\n");

        return buffer.toString();
    }
}
